import http from "@/api";

import { PORT1 } from "@/api/config/servicePort";

export interface OptionType {
  value: string | number;
  label: string;
}

//添加单证初始化数据接口
export const getDocumentInitData = (data: Record<string, any>) =>
  http.post(`${PORT1}/goods-certify/certify-create/view`, { ...data }, { loading: false });


//添加单证初始化数据接口
export const postDocumentFormData = (data: Record<string, any>) =>
  http.post(`${PORT1}/goods-certify/certify-create/create`, { ...data }, { loading: false });

// 获取单证详情
export const getDetail = (goods_certify_id: string, queueId?: string) =>
  http.get<{ goods_certify: Record<string, any>; filter: { [k: string]: OptionType[] } }>(
    `${PORT1}/goods-certify/edit/detail`,
    { goods_certify_id },
    { queueId, loading: false }
  );

// 编辑单证基本信息
export const saveBase = (data: Record<string, any>) =>
  http.post(`${PORT1}/goods-certify/edit/save-base`, { ...data }, { loading: false });

// 获取单证详情表格数据
export const getTableData = (goods_certify_id: string, type: "brand" | "cnCompany" | "supplier" | "file", queueId?: string) =>
  http.get<Array<Record<string, any>>>(
    `${PORT1}/goods-certify/edit/list`,
    { goods_certify_id, type },
    { queueId, loading: false }
  );

// 获取单证工厂下拉选项
export const getCompanyOptions = (type: string = "factory") =>
  http.post<OptionType[]>(`${PORT1}/goods-certify/certify-create/form-select`, { type }, { loading: false });

// 编辑单证工厂信息
export const saveCompany = (data: Record<string, any>) =>
  http.post(`${PORT1}/goods-certify/edit/save-cn-company`, { ...data }, { loading: false });

// 编辑单证附件信息
export const saveFile = (data: Record<string, any>) =>
  http.post(`${PORT1}/goods-certify/edit/save-file`, { ...data }, { loading: false });
